{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "###   **多元统计分析及R语言建模（第五版）**\n",
    "###   本文档是基于Jupyter Notebook编写的\n",
    "###   建议安装anaconda（https://www.anaconda.com/） \n",
    "###   修改时间：王斌会 2020.2.1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "# 1 多元统计分析概述 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "outputs": [],
   "source": [
    "#【输出设置】\n",
    "#setwd(\"D:/mvstats5\")              #设置目录\n",
    "par(mar=c(4,4,1,1),cex=0.75)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeAAAAGkCAMAAADewwbdAAAAM1BMVEUAAABNTU1oaGh8fHyM\njIyampqnp6eysrK9vb3Hx8fQ0NDZ2dnh4eHp6enw8PD/AAD///89ODILAAAACXBIWXMAABJ0\nAAASdAHeZh94AAAR80lEQVR4nO2d2WKDIBBFccnaaPz/r61LFk1cgBlgnNzz0KYpYaae4oII\npgGqMakTAGGBYOVAsHIgWDkQrBwIVg4EKweClQPByoFg5UCwciBYORCsHAhWDgQrB4KVA8HK\ngWDlQLByIFg5EKwcCFYOBCsHgpUDwcqBYOVAsHIgWDkQrBwIVg4EKweClQPByoFg5U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jSBNcDgnRNs3ZFKQKjubafr2YU8okGp6NIU3wA9qmMUdaBaXphnzf\nTJkyiVFN+gTXtAcWb9SNwrEboSbxgrYxZAo+9/tICukFc1TQQ9sYIgVXGWnn2KFHMHFjSBRc\nZ/QnytUIpm4MKYLHE8oUnheg4zpI2zYTJNh3Y7xyoKfAwltOlRcVtQ7ith3OoivaWTQ1iR7/\njfHKgZoCN1eeGT9I2/bUn9ZcyU/FkgUzbAxpgiumGV0E9GTRBXNsDGmCDzzzuxG3bc4zeRD1\nr+DYGNIEM03gR9y2dX83iZgCXTDHxpAmGDADwcqBYOVAsHIgWDkQrBwIVg4EKweClQPByoFg\n5UCwciBYORCsHAhWDgQrB4KVA8HKgWDlQLByIFg5EKwcCFYOBCsHgpUDwcqBYOVAsHIgWDkQ\nrBwIVg4EKweClQPBh8dUDQVxhluhQHCTmXPTTRiYpU4kCBDc/BlTNTV9Th2ZQPCwky517qAh\nuCczJ6U7aAjuaXfSSnfQEDxw0LqDhuCBTO0eGoI7DkbtORYEN/3co43agzAEdzvoi9p+Dgju\nd9CN2p5KCO6ukbql4yqlO2kIHrqi1XZG/7zgw2veb5076Z8XrB0IVg4EKweClQPByoFg5UCw\nciBYORCsHAhWDgQrB4KVA8HKgWDlQLByIFg5EKwcCFYOBCsHgpUDwcqBYOVAsHIgWDkQrBwI\nVg4EKweClQPByoFg5UCwcv4BGnkJzN7HaaoAAAAASUVORK5CYII=",
      "text/plain": [
       "Plot with title \"Histogram of X\""
      ]
     },
     "metadata": {
      "image/png": {
       "height": 210,
       "width": 240
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "X=rnorm(50);                       #产生50个标准正态随机数\n",
    "hist(X,prob=TRUE)                  #做数据的直方图\n",
    "lines(density(X),col='red')        #添加密度函数曲线 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "# 2 多元数据的数学表达 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "## 2.3  数据矩阵及R表示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "12"
      ],
      "text/latex": [
       "12"
      ],
      "text/markdown": [
       "12"
      ],
      "text/plain": [
       "[1] 12"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<style>\n",
       ".list-inline {list-style: none; margin:0; padding: 0}\n",
       ".list-inline>li {display: inline-block}\n",
       ".list-inline>li:not(:last-child)::after {content: \"\\00b7\"; padding: 0 .5ex}\n",
       "</style>\n",
       "<ol class=list-inline><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li></ol>\n"
      ],
      "text/latex": [
       "\\begin{enumerate*}\n",
       "\\item 1\n",
       "\\item 2\n",
       "\\item 3\n",
       "\\item 4\n",
       "\\item 5\n",
       "\\item 6\n",
       "\\item 7\n",
       "\\item 8\n",
       "\\item 9\n",
       "\\end{enumerate*}\n"
      ],
      "text/markdown": [
       "1. 1\n",
       "2. 2\n",
       "3. 3\n",
       "4. 4\n",
       "5. 5\n",
       "6. 6\n",
       "7. 7\n",
       "8. 8\n",
       "9. 9\n",
       "\n",
       "\n"
      ],
      "text/plain": [
       "[1] 1 2 3 4 5 6 7 8 9"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<style>\n",
       ".list-inline {list-style: none; margin:0; padding: 0}\n",
       ".list-inline>li {display: inline-block}\n",
       ".list-inline>li:not(:last-child)::after {content: \"\\00b7\"; padding: 0 .5ex}\n",
       "</style>\n",
       "<ol class=list-inline><li>1</li><li>3</li><li>6</li><li>5</li><li>4</li><li>9</li></ol>\n"
      ],
      "text/latex": [
       "\\begin{enumerate*}\n",
       "\\item 1\n",
       "\\item 3\n",
       "\\item 6\n",
       "\\item 5\n",
       "\\item 4\n",
       "\\item 9\n",
       "\\end{enumerate*}\n"
      ],
      "text/markdown": [
       "1. 1\n",
       "2. 3\n",
       "3. 6\n",
       "4. 5\n",
       "5. 4\n",
       "6. 9\n",
       "\n",
       "\n"
      ],
      "text/plain": [
       "[1] 1 3 6 5 4 9"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#### 创建一个向量\n",
    "x1=c(171,175,159,155,152,158,154,164,168,166,159,164)\n",
    "x2=c(57,64,41,38,35,44,41,51,57,49,47,46)\n",
    "length(x1)  #向量的长度\n",
    "a=1:9; a\n",
    "b=c(1,3,6:4,9); b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A matrix: 2 × 3 of type dbl</caption>\n",
       "<tbody>\n",
       "\t<tr><td>1</td><td>2</td><td>3</td></tr>\n",
       "\t<tr><td>4</td><td>5</td><td>6</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A matrix: 2 × 3 of type dbl\n",
       "\\begin{tabular}{lll}\n",
       "\t 1 & 2 & 3\\\\\n",
       "\t 4 & 5 & 6\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A matrix: 2 × 3 of type dbl\n",
       "\n",
       "| 1 | 2 | 3 |\n",
       "| 4 | 5 | 6 |\n",
       "\n"
      ],
      "text/plain": [
       "     [,1] [,2] [,3]\n",
       "[1,] 1    2    3   \n",
       "[2,] 4    5    6   "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A matrix: 3 × 2 of type dbl</caption>\n",
       "<tbody>\n",
       "\t<tr><td>1</td><td>4</td></tr>\n",
       "\t<tr><td>2</td><td>5</td></tr>\n",
       "\t<tr><td>3</td><td>6</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A matrix: 3 × 2 of type dbl\n",
       "\\begin{tabular}{ll}\n",
       "\t 1 & 4\\\\\n",
       "\t 2 & 5\\\\\n",
       "\t 3 & 6\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A matrix: 3 × 2 of type dbl\n",
       "\n",
       "| 1 | 4 |\n",
       "| 2 | 5 |\n",
       "| 3 | 6 |\n",
       "\n"
      ],
      "text/plain": [
       "     [,1] [,2]\n",
       "[1,] 1    4   \n",
       "[2,] 2    5   \n",
       "[3,] 3    6   "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A matrix: 3 × 2 of type dbl</caption>\n",
       "<tbody>\n",
       "\t<tr><td>1</td><td>4</td></tr>\n",
       "\t<tr><td>2</td><td>5</td></tr>\n",
       "\t<tr><td>3</td><td>6</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A matrix: 3 × 2 of type dbl\n",
       "\\begin{tabular}{ll}\n",
       "\t 1 & 4\\\\\n",
       "\t 2 & 5\\\\\n",
       "\t 3 & 6\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A matrix: 3 × 2 of type dbl\n",
       "\n",
       "| 1 | 4 |\n",
       "| 2 | 5 |\n",
       "| 3 | 6 |\n",
       "\n"
      ],
      "text/plain": [
       "     [,1] [,2]\n",
       "[1,] 1    4   \n",
       "[2,] 2    5   \n",
       "[3,] 3    6   "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A matrix: 2 × 2 of type dbl</caption>\n",
       "<tbody>\n",
       "\t<tr><td>2</td><td> 6</td></tr>\n",
       "\t<tr><td>6</td><td>10</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A matrix: 2 × 2 of type dbl\n",
       "\\begin{tabular}{ll}\n",
       "\t 2 &  6\\\\\n",
       "\t 6 & 10\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A matrix: 2 × 2 of type dbl\n",
       "\n",
       "| 2 |  6 |\n",
       "| 6 | 10 |\n",
       "\n"
      ],
      "text/plain": [
       "     [,1] [,2]\n",
       "[1,] 2     6  \n",
       "[2,] 6    10  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A matrix: 2 × 2 of type dbl</caption>\n",
       "<tbody>\n",
       "\t<tr><td>14</td><td>32</td></tr>\n",
       "\t<tr><td>32</td><td>77</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A matrix: 2 × 2 of type dbl\n",
       "\\begin{tabular}{ll}\n",
       "\t 14 & 32\\\\\n",
       "\t 32 & 77\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A matrix: 2 × 2 of type dbl\n",
       "\n",
       "| 14 | 32 |\n",
       "| 32 | 77 |\n",
       "\n"
      ],
      "text/plain": [
       "     [,1] [,2]\n",
       "[1,] 14   32  \n",
       "[2,] 32   77  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "A=matrix(c(1,4,2,5,3,6),nrow=2,ncol=3); A  #A=matrix(c(1,4,2,5,3,6),2,3); A   \n",
    "B=matrix(c(1,2,3,4,5,6),3,2); B   \n",
    "t(A) #求矩阵转置\n",
    "A[,1:2]+B[1:2,] #矩阵加法\n",
    "C=A%*%B;C       #矩阵乘法  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "## 2.4  数据框及R表示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A data.frame: 12 × 2</caption>\n",
       "<thead>\n",
       "\t<tr><th scope=col>身高</th><th scope=col>体重</th></tr>\n",
       "\t<tr><th scope=col>&lt;dbl&gt;</th><th scope=col>&lt;dbl&gt;</th></tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "\t<tr><td>171</td><td>57</td></tr>\n",
       "\t<tr><td>175</td><td>64</td></tr>\n",
       "\t<tr><td>159</td><td>41</td></tr>\n",
       "\t<tr><td>155</td><td>38</td></tr>\n",
       "\t<tr><td>152</td><td>35</td></tr>\n",
       "\t<tr><td>158</td><td>44</td></tr>\n",
       "\t<tr><td>154</td><td>41</td></tr>\n",
       "\t<tr><td>164</td><td>51</td></tr>\n",
       "\t<tr><td>168</td><td>57</td></tr>\n",
       "\t<tr><td>166</td><td>49</td></tr>\n",
       "\t<tr><td>159</td><td>47</td></tr>\n",
       "\t<tr><td>164</td><td>46</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A data.frame: 12 × 2\n",
       "\\begin{tabular}{ll}\n",
       " 身高 & 体重\\\\\n",
       " <dbl> & <dbl>\\\\\n",
       "\\hline\n",
       "\t 171 & 57\\\\\n",
       "\t 175 & 64\\\\\n",
       "\t 159 & 41\\\\\n",
       "\t 155 & 38\\\\\n",
       "\t 152 & 35\\\\\n",
       "\t 158 & 44\\\\\n",
       "\t 154 & 41\\\\\n",
       "\t 164 & 51\\\\\n",
       "\t 168 & 57\\\\\n",
       "\t 166 & 49\\\\\n",
       "\t 159 & 47\\\\\n",
       "\t 164 & 46\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A data.frame: 12 × 2\n",
       "\n",
       "| 身高 &lt;dbl&gt; | 体重 &lt;dbl&gt; |\n",
       "|---|---|\n",
       "| 171 | 57 |\n",
       "| 175 | 64 |\n",
       "| 159 | 41 |\n",
       "| 155 | 38 |\n",
       "| 152 | 35 |\n",
       "| 158 | 44 |\n",
       "| 154 | 41 |\n",
       "| 164 | 51 |\n",
       "| 168 | 57 |\n",
       "| 166 | 49 |\n",
       "| 159 | 47 |\n",
       "| 164 | 46 |\n",
       "\n"
      ],
      "text/plain": [
       "   身高 体重\n",
       "1  171  57  \n",
       "2  175  64  \n",
       "3  159  41  \n",
       "4  155  38  \n",
       "5  152  35  \n",
       "6  158  44  \n",
       "7  154  41  \n",
       "8  164  51  \n",
       "9  168  57  \n",
       "10 166  49  \n",
       "11 159  47  \n",
       "12 164  46  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "X=data.frame(x1,x2);                #产生由X1和X2构建的数据框\n",
    "Y=data.frame('身高'=x1,'体重'=x2);Y  #赋予数据框新的列标签"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "## 2.5  多元数据的R调用 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 方法一、复制拷贝（最方便）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A data.frame: 5 × 7</caption>\n",
       "<thead>\n",
       "\t<tr><th scope=col>年龄</th><th scope=col>性别</th><th scope=col>风险意识</th><th scope=col>专兼职情况</th><th scope=col>职业状况</th><th scope=col>教育程度</th><th scope=col>投资结果</th></tr>\n",
       "\t<tr><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "\t<tr><td>20-29</td><td>男</td><td>有</td><td>兼职</td><td>金融</td><td>高中</td><td>赚钱</td></tr>\n",
       "\t<tr><td>50-59</td><td>女</td><td>有</td><td>兼职</td><td>科教</td><td>中学</td><td>持平</td></tr>\n",
       "\t<tr><td>40-49</td><td>女</td><td>无</td><td>专职</td><td>科教</td><td>中学</td><td>赔钱</td></tr>\n",
       "\t<tr><td>30-39</td><td>男</td><td>有</td><td>兼职</td><td>工人</td><td>中专</td><td>赚钱</td></tr>\n",
       "\t<tr><td>50-59</td><td>女</td><td>有</td><td>专职</td><td>农民</td><td>大专</td><td>赚钱</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A data.frame: 5 × 7\n",
       "\\begin{tabular}{lllllll}\n",
       " 年龄 & 性别 & 风险意识 & 专兼职情况 & 职业状况 & 教育程度 & 投资结果\\\\\n",
       " <fct> & <fct> & <fct> & <fct> & <fct> & <fct> & <fct>\\\\\n",
       "\\hline\n",
       "\t 20-29 & 男 & 有 & 兼职 & 金融 & 高中 & 赚钱\\\\\n",
       "\t 50-59 & 女 & 有 & 兼职 & 科教 & 中学 & 持平\\\\\n",
       "\t 40-49 & 女 & 无 & 专职 & 科教 & 中学 & 赔钱\\\\\n",
       "\t 30-39 & 男 & 有 & 兼职 & 工人 & 中专 & 赚钱\\\\\n",
       "\t 50-59 & 女 & 有 & 专职 & 农民 & 大专 & 赚钱\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A data.frame: 5 × 7\n",
       "\n",
       "| 年龄 &lt;fct&gt; | 性别 &lt;fct&gt; | 风险意识 &lt;fct&gt; | 专兼职情况 &lt;fct&gt; | 职业状况 &lt;fct&gt; | 教育程度 &lt;fct&gt; | 投资结果 &lt;fct&gt; |\n",
       "|---|---|---|---|---|---|---|\n",
       "| 20-29 | 男 | 有 | 兼职 | 金融 | 高中 | 赚钱 |\n",
       "| 50-59 | 女 | 有 | 兼职 | 科教 | 中学 | 持平 |\n",
       "| 40-49 | 女 | 无 | 专职 | 科教 | 中学 | 赔钱 |\n",
       "| 30-39 | 男 | 有 | 兼职 | 工人 | 中专 | 赚钱 |\n",
       "| 50-59 | 女 | 有 | 专职 | 农民 | 大专 | 赚钱 |\n",
       "\n"
      ],
      "text/plain": [
       "  年龄  性别 风险意识 专兼职情况 职业状况 教育程度 投资结果\n",
       "1 20-29 男   有       兼职       金融     高中     赚钱    \n",
       "2 50-59 女   有       兼职       科教     中学     持平    \n",
       "3 40-49 女   无       专职       科教     中学     赔钱    \n",
       "4 30-39 男   有       兼职       工人     中专     赚钱    \n",
       "5 50-59 女   有       专职       农民     大专     赚钱    "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在Excel文件mvstats5.xlsx的表单d2.1中选择A1:G6，并复制到剪切板\n",
    "dat=read.table(\"clipboard\",header=T);dat  #将剪切板数据读入数据框dat中"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 方法二、csv逗号文本格式（最通用）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A data.frame: 6 × 7</caption>\n",
       "<thead>\n",
       "\t<tr><th></th><th scope=col>年龄</th><th scope=col>性别</th><th scope=col>风险意识</th><th scope=col>专兼职情况</th><th scope=col>职业状况</th><th scope=col>教育程度</th><th scope=col>投资结果</th></tr>\n",
       "\t<tr><th></th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th><th scope=col>&lt;fct&gt;</th></tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>1</th><td>20-29</td><td>男</td><td>有</td><td>兼职</td><td>金融</td><td>高中</td><td>赚钱</td></tr>\n",
       "\t<tr><th scope=row>2</th><td>50-59</td><td>女</td><td>有</td><td>兼职</td><td>科教</td><td>中学</td><td>持平</td></tr>\n",
       "\t<tr><th scope=row>3</th><td>40-49</td><td>女</td><td>无</td><td>专职</td><td>科教</td><td>中学</td><td>赔钱</td></tr>\n",
       "\t<tr><th scope=row>4</th><td>30-39</td><td>男</td><td>有</td><td>兼职</td><td>工人</td><td>中专</td><td>赚钱</td></tr>\n",
       "\t<tr><th scope=row>5</th><td>50-59</td><td>女</td><td>有</td><td>专职</td><td>农民</td><td>大专</td><td>赚钱</td></tr>\n",
       "\t<tr><th scope=row>6</th><td>40-49</td><td>女</td><td>有</td><td>兼职</td><td>管理</td><td>小学</td><td>赚钱</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A data.frame: 6 × 7\n",
       "\\begin{tabular}{r|lllllll}\n",
       "  & 年龄 & 性别 & 风险意识 & 专兼职情况 & 职业状况 & 教育程度 & 投资结果\\\\\n",
       "  & <fct> & <fct> & <fct> & <fct> & <fct> & <fct> & <fct>\\\\\n",
       "\\hline\n",
       "\t1 & 20-29 & 男 & 有 & 兼职 & 金融 & 高中 & 赚钱\\\\\n",
       "\t2 & 50-59 & 女 & 有 & 兼职 & 科教 & 中学 & 持平\\\\\n",
       "\t3 & 40-49 & 女 & 无 & 专职 & 科教 & 中学 & 赔钱\\\\\n",
       "\t4 & 30-39 & 男 & 有 & 兼职 & 工人 & 中专 & 赚钱\\\\\n",
       "\t5 & 50-59 & 女 & 有 & 专职 & 农民 & 大专 & 赚钱\\\\\n",
       "\t6 & 40-49 & 女 & 有 & 兼职 & 管理 & 小学 & 赚钱\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A data.frame: 6 × 7\n",
       "\n",
       "| <!--/--> | 年龄 &lt;fct&gt; | 性别 &lt;fct&gt; | 风险意识 &lt;fct&gt; | 专兼职情况 &lt;fct&gt; | 职业状况 &lt;fct&gt; | 教育程度 &lt;fct&gt; | 投资结果 &lt;fct&gt; |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 1 | 20-29 | 男 | 有 | 兼职 | 金融 | 高中 | 赚钱 |\n",
       "| 2 | 50-59 | 女 | 有 | 兼职 | 科教 | 中学 | 持平 |\n",
       "| 3 | 40-49 | 女 | 无 | 专职 | 科教 | 中学 | 赔钱 |\n",
       "| 4 | 30-39 | 男 | 有 | 兼职 | 工人 | 中专 | 赚钱 |\n",
       "| 5 | 50-59 | 女 | 有 | 专职 | 农民 | 大专 | 赚钱 |\n",
       "| 6 | 40-49 | 女 | 有 | 兼职 | 管理 | 小学 | 赚钱 |\n",
       "\n"
      ],
      "text/plain": [
       "  年龄  性别 风险意识 专兼职情况 职业状况 教育程度 投资结果\n",
       "1 20-29 男   有       兼职       金融     高中     赚钱    \n",
       "2 50-59 女   有       兼职       科教     中学     持平    \n",
       "3 40-49 女   无       专职       科教     中学     赔钱    \n",
       "4 30-39 男   有       兼职       工人     中专     赚钱    \n",
       "5 50-59 女   有       专职       农民     大专     赚钱    \n",
       "6 40-49 女   有       兼职       管理     小学     赚钱    "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dat=read.csv('d2.1.csv')  #d2.1.csv数据读入数据框dat中\n",
    "head(dat)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 方法三、excel格式数据（最全面）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Warning message:\n",
      "\"package 'openxlsx' was built under R version 3.6.2\"\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<caption>A data.frame: 6 × 7</caption>\n",
       "<thead>\n",
       "\t<tr><th></th><th scope=col>年龄</th><th scope=col>性别</th><th scope=col>风险意识</th><th scope=col>专兼职情况</th><th scope=col>职业状况</th><th scope=col>教育程度</th><th scope=col>投资结果</th></tr>\n",
       "\t<tr><th></th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th><th scope=col>&lt;chr&gt;</th></tr>\n",
       "</thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>1</th><td>20-29</td><td>男</td><td>有</td><td>兼职</td><td>金融</td><td>高中</td><td>赚钱</td></tr>\n",
       "\t<tr><th scope=row>2</th><td>50-59</td><td>女</td><td>有</td><td>兼职</td><td>科教</td><td>中学</td><td>持平</td></tr>\n",
       "\t<tr><th scope=row>3</th><td>40-49</td><td>女</td><td>无</td><td>专职</td><td>科教</td><td>中学</td><td>赔钱</td></tr>\n",
       "\t<tr><th scope=row>4</th><td>30-39</td><td>男</td><td>有</td><td>兼职</td><td>工人</td><td>中专</td><td>赚钱</td></tr>\n",
       "\t<tr><th scope=row>5</th><td>50-59</td><td>女</td><td>有</td><td>专职</td><td>农民</td><td>大专</td><td>赚钱</td></tr>\n",
       "\t<tr><th scope=row>6</th><td>40-49</td><td>女</td><td>有</td><td>兼职</td><td>管理</td><td>小学</td><td>赚钱</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "A data.frame: 6 × 7\n",
       "\\begin{tabular}{r|lllllll}\n",
       "  & 年龄 & 性别 & 风险意识 & 专兼职情况 & 职业状况 & 教育程度 & 投资结果\\\\\n",
       "  & <chr> & <chr> & <chr> & <chr> & <chr> & <chr> & <chr>\\\\\n",
       "\\hline\n",
       "\t1 & 20-29 & 男 & 有 & 兼职 & 金融 & 高中 & 赚钱\\\\\n",
       "\t2 & 50-59 & 女 & 有 & 兼职 & 科教 & 中学 & 持平\\\\\n",
       "\t3 & 40-49 & 女 & 无 & 专职 & 科教 & 中学 & 赔钱\\\\\n",
       "\t4 & 30-39 & 男 & 有 & 兼职 & 工人 & 中专 & 赚钱\\\\\n",
       "\t5 & 50-59 & 女 & 有 & 专职 & 农民 & 大专 & 赚钱\\\\\n",
       "\t6 & 40-49 & 女 & 有 & 兼职 & 管理 & 小学 & 赚钱\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "A data.frame: 6 × 7\n",
       "\n",
       "| <!--/--> | 年龄 &lt;chr&gt; | 性别 &lt;chr&gt; | 风险意识 &lt;chr&gt; | 专兼职情况 &lt;chr&gt; | 职业状况 &lt;chr&gt; | 教育程度 &lt;chr&gt; | 投资结果 &lt;chr&gt; |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| 1 | 20-29 | 男 | 有 | 兼职 | 金融 | 高中 | 赚钱 |\n",
       "| 2 | 50-59 | 女 | 有 | 兼职 | 科教 | 中学 | 持平 |\n",
       "| 3 | 40-49 | 女 | 无 | 专职 | 科教 | 中学 | 赔钱 |\n",
       "| 4 | 30-39 | 男 | 有 | 兼职 | 工人 | 中专 | 赚钱 |\n",
       "| 5 | 50-59 | 女 | 有 | 专职 | 农民 | 大专 | 赚钱 |\n",
       "| 6 | 40-49 | 女 | 有 | 兼职 | 管理 | 小学 | 赚钱 |\n",
       "\n"
      ],
      "text/plain": [
       "  年龄  性别 风险意识 专兼职情况 职业状况 教育程度 投资结果\n",
       "1 20-29 男   有       兼职       金融     高中     赚钱    \n",
       "2 50-59 女   有       兼职       科教     中学     持平    \n",
       "3 40-49 女   无       专职       科教     中学     赔钱    \n",
       "4 30-39 男   有       兼职       工人     中专     赚钱    \n",
       "5 50-59 女   有       专职       农民     大专     赚钱    \n",
       "6 40-49 女   有       兼职       管理     小学     赚钱    "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#library(readxl)   #加载包readxl, 需先安装包, install.packages('readxl') \n",
    "#d2.1=read_excel('mvstats5.xlsx',sheet='d2.1') #读取mvstats5.xlsx表格d2.2数据\n",
    "library(openxlsx)  # 加载包openxlsx，需先安装：install.packages('openxlsx') \n",
    "d2.1=read.xlsx('mvstats5.xlsx','d2.1') #读取mvstats5.xlsx表格d2.1数据\n",
    "head(d2.1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "source": [
    "## 2.6  多元数据简单R分析 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "年龄\n",
       "    *  0-19 20-29 30-39 40-49 50-59   60- \n",
       "   20     3    92   167   157    51    24 "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeAAAAGkCAMAAADewwbdAAAAQlBMVEUAAAAAAP8AzQAA//9N\nTU1oaGh8fHyMjIyampqnp6eysrK9vb3Hx8fQ0NDZ2dnh4eHp6enw8PD/AAD/AP///wD////v\nbhP8AAAACXBIWXMAABJ0AAASdAHeZh94AAAKLklEQVR4nO2dbWOCNhhFsw2LSC2yLf//r05Q\nW6qJ8ARfkrtzPrS2aXLDc6pCWo3zII179wTguSBYHASLg2BxECwOgsVBsDgIFgfB4iBYHASL\ng2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwOgsV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Lg2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwO\ngsVBsDgIFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB4iBY\nHASLg2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB4vwHuUUkWiVydd4AAAAA\nSUVORK5CYII=",
      "text/plain": [
       "plot without title"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 210,
       "width": 240
      }
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "       性别\n",
       "年龄     男  女\n",
       "  *       9  11\n",
       "  0-19    2   1\n",
       "  20-29  69  23\n",
       "  30-39 101  66\n",
       "  40-49  89  68\n",
       "  50-59  24  27\n",
       "  60-    15   9"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeAAAAGkCAMAAADewwbdAAAADFBMVEUAAACt2Ob/5OH////C\nZ2Y1AAAACXBIWXMAABJ0AAASdAHeZh94AAAJZklEQVR4nO3djXbaOBBAYXX9/u+8TcOPbAz2\nYBlGV/ee04ZNSDLRtzKEpLhMhq58ewA7N4HhCQxPYHgCwxMYnsDwBIYnMDyB4QkMT2B4AsMT\nGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDwBIYnMDyB4QkMT2B4\nAsMTGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDwBIYnMDyB4QkM\nT2B4AsMTGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDwBIYnMDyB\n4QkMT2B4AsMTGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDwBIYn\nMDyB4QkMT2B4AsMTGJ7A8ASGJzA8geEJDE9geALDEzhaKfOXD2//3Ch7SjZOB5XFy5+L874y\n1rNyTdNDNfBs9crDazKUbqD0/WN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+uXB9m1O1nVYia6I51mkE/3HHnX\nbWi5PQxdn8Tp/sHPGjtcnkm+UFlt37vebnFLvXHrBy1zLG2OKfqr3A/T9Z2s6zdIeW6Fc0zR\nXdV3vtVR+tkJFr9Zjil6q/6J0uJovHaCxW+WY4pue3UkzrG0Oaaw0xIYnsDwBIYnMDyB4QkM\nT2B4AsMTGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDwBIYnMDyB\n4QkMT2B4AsMTGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDwBIYn\nMDyB4QkMT2B4AsMTGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDw\nBIYnMDyB4QkMT2B4AsMTGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMY\nnsDwBIYnMDyB4QkMT2B4AsMTGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgC\nwxMYnsDwBIYnMDyB4QkMT2B4AsMTGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxP\nYHj/Ay5665/PTxVkAAAAAElFTkSuQmCC",
      "text/plain": [
       "plot without title"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 210,
       "width": 240
      }
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeAAAAGkCAMAAADewwbdAAAAQlBMVEUAAAAAAP8AzQAA//9N\nTU1oaGh8fHyMjIyampqnp6eysrK9vb3Hx8fQ0NDZ2dnh4eHp6enw8PD/AAD/AP///wD////v\nbhP8AAAACXBIWXMAABJ0AAASdAHeZh94AAAIyklEQVR4nO3djXLaRhRA4W0rfm1iaMv7v2oN\nxsEOwkGru9bV6TkzTehMxV7rizCoyaYcDV2ZegBrm8DwBIYnMDyB4QkMT2B4AsMTGJ7A8ASG\nJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHg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HkCV21G2g/c\nl8DTAlduRtqP+fdtAk8MXLkZ6WyBx7zKzBK4civD2QL3jPjwjLME/s1mpPde3h6/Or6n/i8t\nV5VC719N5XEDrmCbshHfgx/djNSmrPoF4PHNSG3KRnwOfnQzUpuyb7iTZVMmMDyB4QkMT2B4\nAsMTGJ7A8ASGJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDwBIY3O+DS+zBf\nY/9UYFRJxni8uD9Y2bYsw2WZ4+HK9cfUs2cZLsscDzcT4DQvL1nmeLiZvESXmwcTNfX6g8t+\nBUdvwTB6nmmXH1524LfeWKfGPc8w9QBDy3NtfNWHX4YTl2GGQaW5NL5M4HFlB774ZpgywwxD\nSvUG5m55LuAcQwyufPopXUXgkSUHvrzQTD3EuRxTDKz88nPKkhBnmGFo7ycuxQm812m4DMTT\nTzC481l7/ydpeX4NTj7A4H6euulP3r0+TDb5jJMPMKwPqlknT/YLL9UwFp/A8ASGJzA8geEJ\nDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDwBIYnMDyB4QkMT2B4AsMTGJ7A8ASGJzA8\ngeEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDwBIYnMDyB4QkMT2B4AsMTGJ7A8ASG\nJzA8geEJDE9geALDExiewPAEhicwPIHhCQxPYHgCwxMYnsDwBIYnMDyB4QkMT2B4AsMTGJ7A\n8ASGJzA8geH9B+oP0/TUEIwDAAAAAElFTkSuQmCC",
      "text/plain": [
       "plot without title"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 210,
       "width": 240
      }
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "           投资结果 持平 赔钱 赚钱\n",
       "年龄  性别                        \n",
       "*     男               4    3    2\n",
       "      女               3    7    1\n",
       "0-19  男               0    0    2\n",
       "      女               1    0    0\n",
       "20-29 男              21   17   31\n",
       "      女              10    7    6\n",
       "30-39 男              31   30   40\n",
       "      女              30   20   16\n",
       "40-49 男              31   30   28\n",
       "      女              25   30   13\n",
       "50-59 男               5   11    8\n",
       "      女               8   10    9\n",
       "60-   男               7    5    3\n",
       "      女               2    5    2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "           投资结果 持平 赔钱 赚钱\n",
       "性别 年龄                         \n",
       "男   *                 4    3    2\n",
       "     0-19              0    0    2\n",
       "     20-29            21   17   31\n",
       "     30-39            31   30   40\n",
       "     40-49            31   30   28\n",
       "     50-59             5   11    8\n",
       "     60-               7    5    3\n",
       "女   *                 3    7    1\n",
       "     0-19              1    0    0\n",
       "     20-29            10    7    6\n",
       "     30-39            30   20   16\n",
       "     40-49            25   30   13\n",
       "     50-59             8   10    9\n",
       "     60-               2    5    2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "              年龄  * 0-19 20-29 30-39 40-49 50-59 60-\n",
       "性别 投资结果                                         \n",
       "男   持平           4    0    21    31    31     5   7\n",
       "     赔钱           3    0    17    30    30    11   5\n",
       "     赚钱           2    2    31    40    28     8   3\n",
       "女   持平           3    1    10    30    25     8   2\n",
       "     赔钱           7    0     7    20    30    10   5\n",
       "     赚钱           1    0     6    16    13     9   2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeAAAAGkCAMAAADewwbdAAAAM1BMVEUAAABNTU1oaGh8fHyM\njIyampqnp6eysrK9vb3Hx8fQ0NDZ2dnh4eHp6enw8PD/AAD///89ODILAAAACXBIWXMAABJ0\nAAASdAHeZh94AAAKU0lEQVR4nO2d0WKiOhRFgwJai1z//2uvELVUI5aDSM6etR6mtoHskCUi\nmXoaTiBNWHsAsCwIFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwOgsVBsDgI\nFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB4iBYHASLg2Bx\nECwOgsVBsDgI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BYHASLg2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB\n4iBYHASLg2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwO\ngsVBsDgIFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB4iBYHASLg2BxECwOgsVBsDgIFgfB4iBY\nHASLg2BxECzO/3BGNj/lFXDuAAAAAElFTkSuQmCC",
      "text/plain": [
       "plot without title"
      ]
     },
     "metadata": {
      "image/png": {
       "height": 210,
       "width": 240
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "attach(d2.1)   #绑定数据\n",
    "  table(年龄)  #一维列联表\n",
    "  barplot(table(年龄),col=1:7)#条形图\n",
    "  pie(table(投资结果))#饼图\n",
    "  table(年龄,性别) #二维列联表\n",
    "  barplot(table(年龄,性别),beside=T,col=1:7)#以性别分组的年龄条图\n",
    "  barplot(table(性别,年龄),beside=T,col=1:2)#以年龄分组的性别条图\n",
    "  ftable(年龄,性别,投资结果) #以年龄、性别排列的结果频数三维列联表\n",
    "  ftable(性别,年龄,投资结果)#以性别、年龄排列的结果频数三维列联表\n",
    "  (ft=ftable(性别,投资结果,年龄))#显示以性别、结果排列的年龄频数三维列联表\n",
    "detach(d2.1) #解除数据绑定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "extensions": {
     "jupyter_dashboards": {
      "version": 1,
      "views": {
       "grid_default": {
        "hidden": true
       },
       "report_default": {}
      }
     }
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "extensions": {
   "jupyter_dashboards": {
    "activeView": "grid_default",
    "version": 1,
    "views": {
     "grid_default": {
      "cellMargin": 10,
      "defaultCellHeight": 20,
      "maxColumns": 12,
      "name": "grid",
      "type": "grid"
     },
     "report_default": {
      "name": "report",
      "type": "report"
     }
    }
   }
  },
  "hide_input": false,
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.6.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {
    "height": "236px",
    "width": "358px"
   },
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "281px",
    "left": "907px",
    "top": "137.667px",
    "width": "221px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "position": {
    "height": "144px",
    "left": "916px",
    "right": "20px",
    "top": "573px",
    "width": "350px"
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
